package com.joven.shelltest.utils.delayed;

import lombok.AllArgsConstructor;

import java.util.concurrent.DelayQueue;

/**
 * @Author: wzj
 * @Date: 2024/2/18 15:39
 */
@AllArgsConstructor
public class Consumer implements Runnable{
    /** 延时队列 ,消费者从其中获取消息进行消费 */
    private DelayQueue<Message> queue;

    @Override
    public void run() {
        while (true) {
            try {
                Message take = queue.take();
                System.out.println("消费消息id：" + take.getId() + " 消息体：" + take.getBody());
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }
}
